package com.breakfast.fun.ui.mall;

import com.breakfast.fun.Constant;
import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseFragment;
import com.breakfast.fun.data.entity.mall.MallBanner;
import com.breakfast.fun.event.RefreshEvent;
import com.breakfast.fun.view.layout.TRecyclerView;
import com.breakfast.fun.view.viewholder.AbroadBannerVH;
import com.breakfast.fun.view.viewholder.AbroadItemVH;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.Bind;

/**
 * Created by yukai on 16/10/1.
 */

public class AbroadFragment extends BaseFragment<AbroadPresenter, AbroadModel> implements AbroadContract.View {

    @Bind(R.id.trv_abroad)
    TRecyclerView mTrvAbroad;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_abroad;
    }

    @Override
    public void initView() {
        EventBus.getDefault().register(this);

    }


    @Subscribe
    public void onEvent(RefreshEvent event) {
        if (event.getActivityName().equals(getClass().getSimpleName())) {
            presenter.getAbroad();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void showAbroad(MallBanner mallBanner) {
        getActivity().getIntent().putExtra(Constant.HEAD_DATA
                , mallBanner.getData());
        mTrvAbroad.setView(AbroadItemVH.class)
                .setHeadView(AbroadBannerVH.class)
                .setIsRefreshable(true)
                .fetch();
    }
}
